package cn.com.io.day20151214.control;

import cn.com.io.day20151214.pojo.Person;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 对象流ObjectOutputStream, 对象序列化
 */
public class WriteObject {
    public static void main(String[] args) throws IOException {
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("Object.txt"));//创建一个ObjectOutputStream输出流
            Person person = new Person("张三",34);
            oos.writeObject(person);//将person对象写入输出流
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if ( oos != null){
                oos.close();
            }
        }
    }
}
